﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

using Magnet.Engine.Entities;

namespace Magnet.Engine
{
    public class UserInterface
    {
        private static Texture2D sharkFin;
        private static Texture2D slomoFiller;
        private static Texture2D slomoMeter;

        private static Vector2 sharkFinPosition;
        private static float sharkFinLeftBoundry;
        private static float sharkFinRightBoundry;
        private static float sharkFinSpeed;
        private static int direction;

        private static Vector2 slomoMeterPosition;
        private static Vector2 slomoFillerPosition;

        public static void Initialize()
        {
            slomoMeterPosition = new Vector2(910f, 350f);
            slomoFillerPosition = new Vector2(slomoMeterPosition.X + 20,
                slomoMeterPosition.Y + 95);

            direction = 1;
            sharkFinSpeed = 100f;
            sharkFinPosition = new Vector2(400f, 700f);
            sharkFinLeftBoundry = 150f;
            sharkFinRightBoundry = 900f;
        }

        public static void LoadContent(ContentManager content)
        {
            sharkFin = content.Load<Texture2D>("UI\\sharkfin");
            slomoFiller = content.Load<Texture2D>("UI\\slomo_filler");
            slomoMeter = content.Load<Texture2D>("UI\\slomo_meter");
        }

        public static void Update(float elapsedSeconds)
        {
            float xPosition = sharkFinPosition.X;

            xPosition += direction * sharkFinSpeed * elapsedSeconds;

            if (xPosition < sharkFinLeftBoundry)
            {
                direction = -direction;
                xPosition = sharkFinLeftBoundry;
            }
            else if (xPosition > sharkFinRightBoundry)
            {
                direction = -direction;
                xPosition = sharkFinRightBoundry;
            }

            sharkFinPosition.X = xPosition;
        }

        public static void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(slomoMeter, slomoMeterPosition, Color.White);

            float height = slomoFiller.Height * (PlayerManager.bulletTimer / PlayerManager.bulletLimit);

            spriteBatch.Draw(slomoFiller,
                new Rectangle((int)slomoFillerPosition.X,
                    (int)(slomoFillerPosition.Y + (slomoFiller.Height - height)),
                    slomoFiller.Width, (int)(height)), Color.White);

            //spriteBatch.Draw(slomoFiller, slomoFillerPosition, Color.White);

            spriteBatch.Draw(sharkFin, sharkFinPosition, null, Color.White, 0f,
                new Vector2(sharkFin.Width / 2f, sharkFin.Height / 2f), 0.5f,
                ((direction == 1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None), 0f);
        }
    }
}
